// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import "babel-polyfill"
import 'url-search-params-polyfill';
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import MintUI from 'mint-ui'
//底部工具栏
import FootNav from '@/components/common/FootNav'

Vue.component("foot-nav", FootNav)
//顶部导航条
import HeadNav from '@/components/common/HeadNav'

Vue.component("head-nav", HeadNav)
// import { Button, Cell } from 'mint-ui'
import './assets/css/base.less'
import 'mint-ui/lib/style.css'
import less from 'less'
// import './assets/css/mymint.less' //自定义mint样式
import './assets/js/base.js'


Vue.prototype.$less = less;
import {
  Indicator
} from "mint-ui";
import VueBarcode from '@xkeshi/vue-barcode'
import { Util } from './utils/util'


Vue.component('barcode', VueBarcode);

Vue.prototype.host = {
  filehost: '/api/lb_accessory_file_open.action?id='
}
// Vue.prototype.isRelUrl = 'lb';
let api = 'lb';
Vue.prototype.isRelUrl = api;
Vue.prototype.isShareUrl = `http://${api}.ruitaianke.com/lb/#/signed`;
Vue.prototype.isGameUrl = `http://${api}.ruitaianke.com/lb/lebingame/`;
Vue.prototype.$util = new Util();
import axios from 'axios'

Vue.prototype.$ajax = axios;
// 请求拦截（配置发送请求的信息）
axios.interceptors.request.use(function (config) {
  // 处理请求之前的配置
  // console.log("请求前拦截");
  if (config.url !="/api/getCjhyYhqById.action" && config.url !== '/api/getUserOrder.action' && config.url !== '/api/getHdUserZjJp.action' && config.url !== '/api/cKtcqHx.action') {
    Indicator.close();
    Indicator.open('加载中...');
  }
  return config;
}, function (error) {
  // 请求失败的处理

  return Promise.reject(error);
});


// 响应拦截（配置请求回来的信息）
axios.interceptors.response.use(function (response) {
  // 处理响应数据
  console.log("响应");
  Indicator.close();
  return response;
}, function (error) {
  // 处理响应失败
  // Indicator.open('加载失败...');
  setTimeout(function () {
    Indicator.close();
  }, 200)
  return Promise.reject(error);
});


Vue.use(MintUI)
// Vue.use(Button)
// Vue.use(Cell)
Vue.config.productionTip = false


/* 路由发生变化修改页面title */
store.state.title = router.history.current.meta.title

router.beforeEach((to, from, next) => {
  if (to.path == '/error') {
    next();
  } else if (to.path == '/aboutlebin' || to.path == '/agreement') {
    next();
  } else {
    let r_url = `http://${api}.ruitaianke.com/lb`;
    // let r_url = "http://lbtest.ruitaianke.com/lb";
    // let r_url = "http://127.0.0.1:82";
    let userinfo = JSON.parse(sessionStorage.getItem("userinfo"));
    if (to.meta.title) {
      store.state.title = to.meta.title
      document.title = store.state.title
    }

    if (userinfo == null || (userinfo.vipcode == "")) {
      let openid = "";
      let vipcode = "";
      if (to.query.openid != undefined) {
        openid = to.query.openid;
      }
      if (to.query.vipcode != undefined) {
        vipcode = to.query.vipcode;
      }
      if (openid != "") {
        userinfo = {
          openid: openid,
          vipcode: vipcode
        }
        sessionStorage.setItem("userinfo", JSON.stringify(userinfo));
      }
    }

    userinfo = JSON.parse(sessionStorage.getItem("userinfo"));
    if (userinfo == null || (userinfo.vipcode == "" && userinfo.openid == "")) {
      window.location.href = `http://${api}.ruitaianke.com/wx_next_bind.action?redirect=wx_user_bind.action?url=` + r_url + "/%2523/" + to.path.replace("/", "");
    }
    let notoarr = ["faddish","register", "willsave", "bind", "buy5", "bindold", "rapticket", "about", "score", "faddishdetail", "rapdetail", "signed", "wallet", "faddishdetail", "rapdetail", "scoredetail", "shequnlist", "sendtalk", "questionnaire", "buycommon", "FlowDetail", "burstinglist", "burstingarticle"]
    if (userinfo.vipcode == "") {
      if (notoarr.indexOf(to.path.replace("/", "").split("/")[0]) != -1 || to.path == '/baskphoto/list' || to.path.indexOf('/baskphoto/article') !== -1) {
        console.log("不跳转页面")
      } else {
        window.location.href = `http://${api}.ruitaianke.com/wx_next_bind.action?redirect=wx_user_bind.action?url=` + r_url + "/%2523/register";
      }
    }

    // sessionStorage.setItem("userinfo"," {\"openid\":\"oEqvxwMd990Akg-qfRjT5wpdVaCw\",\"vipcode\":\"\"}");
    let isly = false;
    if (to.query.openid != null) {
      let query_new = {};
      for (var p in to.query) {
        if (p != "openid" && p != "vipcode") {
          query_new[p] = to.query[p];
        }
      }
      next({
        path: to.path,
        query: query_new
      })
      isly = true;

    }
    if (!isly) {
      next();
    }
  }
})

Vue.mixin({

  computed: {
    backgroundColor() {
      return {
        backgroundColor: store.getters.get_primary_color
      }
    },
    textColor() {
      return {
        color: store.getters.get_primary_color
      }
    },
    primaryColor() {
      return store.getters.get_primary_color
    }
  }
})


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})

